home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Library / Manuels & Misc / Assembly / AOA.ZIP / CH06 / PGM6_7.ASM < prev    next >
Encoding:
Assembly Source File  |  1994-10-10  |  2.4 KB  |  119 lines

  1. ; Unconditional Jumps
  2.  
  3.         .386
  4.         option    segment:use16
  5.  
  6. dseg        segment    para public 'data'
  7.  
  8.  
  9. ; Pointers to statements in the code segment
  10.  
  11. IndPtr1        word    IndTarget2
  12. IndPtr2        dword    IndTarget3
  13.  
  14.  
  15.  
  16. dseg        ends
  17.  
  18.  
  19. cseg        segment    para public 'code'
  20.         assume    cs:cseg, ds:dseg
  21.  
  22. Main        proc
  23.         mov    ax, dseg
  24.         mov    ds, ax
  25.         mov    es, ax
  26.  
  27. ; JMP instructions transfer control to the
  28. ; location specified in the operand field.
  29. ; This is typically a label that appears
  30. ; in the program.
  31. ;
  32. ; There are many variants of the JMP
  33. ; instruction.  The first is a two-byte
  34. ; opcode that transfers control to +/-128
  35. ; bytes around the current instruction:
  36.  
  37.         jmp    CloseLoc
  38.         nop
  39. CloseLoc:
  40.  
  41.  
  42. ; The next form is a three-byte instruction
  43. ; that allows you to jump anywhere within
  44. ; the current code segment.  Normally, the
  45. ; assembler would pick the shortest version
  46. ; of a given JMP instruction, the "near ptr"
  47. ; operand on the following instruction
  48. ; forces a near (three byte) JMP:
  49.  
  50.  
  51.         jmp    near ptr NearLoc
  52.         nop
  53. NearLoc:
  54.  
  55.  
  56. ; The third form to consider is a five-byte
  57. ; instruction that provides a full segmented
  58. ; address operand.  This form of the JMP
  59. ; instruction lets you transfer control any-
  60. ; where in the program, even to another
  61. ; segment.  The "far ptr" operand forces
  62. ; this form of the JMP instruction:
  63.  
  64.         jmp    far ptr FarLoc
  65.         nop
  66. FarLoc:
  67.  
  68.  
  69. ; You can also load the target address of a
  70. ; near JMP into a register and jump indirectly
  71. ; to the target location.  Note that you can
  72. ; use any 80x86 general purpose register to
  73. ; hold this address; you are not limited to
  74. ; the BX, SI, DI, or BP registers.
  75.  
  76.         lea    dx, IndTarget
  77.         jmp    dx
  78.         nop
  79. IndTarget:
  80.  
  81.  
  82. ; You can even jump indirect through a memory
  83. ; variable.  That is, you can jump though a
  84. ; pointer variable directly without having to
  85. ; first load the pointer variable into a reg-
  86. ; ister (Chapter Six describes why the following
  87. ; labels need two colons).
  88.  
  89.         jmp    IndPtr1
  90.         nop
  91. IndTarget2::
  92.  
  93.  
  94. ; You can even execute a far jump indirect
  95. ; through memory.  Just specify a dword
  96. ; variable in the operand field of a JMP
  97. ; instruction:
  98.  
  99.         jmp    IndPtr2
  100.         nop
  101. IndTarget3::
  102.  
  103.  
  104.  
  105. Quit:        mov    ah, 4ch
  106.         int    21h
  107. Main        endp
  108.  
  109. cseg        ends
  110.  
  111. sseg        segment    para stack 'stack'
  112. stk        byte    1024 dup ("stack   ")
  113. sseg        ends
  114.  
  115. zzzzzzseg    segment    para public 'zzzzzz'
  116. LastBytes    byte    16 dup (?)
  117. zzzzzzseg    ends
  118.         end    Main
  119.